import { MigrationInterface, QueryRunner } from "typeorm";

export class InitData1703734168000 implements MigrationInterface {
  name = "InitData1703734168000";

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query('INSERT INTO `role`(`id`, `name`) VALUES (1, "管理员")');
    // 初始化管理员, admin - 123456
    await queryRunner.query('INSERT INTO `user`(`id`, `username`, `nickname`, `password`) VALUES (1, "admin", "admin", "$argon2id$v=19$m=65536,t=3,p=4$rYR/g9bENYcxCroKmoH8Qw$kExdXU2nRfdD8/2z+mwmI7x8rRdHInQoqYU8ZUiSSW4")');
    await queryRunner.query('INSERT INTO `user_role`(`user_id`, `role_id`) VALUES (1, 1)')
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query('DELETE FROM `role` WHERE `id` = 1')
    await queryRunner.query('DELETE FROM `user` WHERE `id` = 1')
    await queryRunner.query('DELETE FROM `user_role` WHERE `user_id` = 1 AND `role_id` = 1')
  }
}
